const api = require("@/api/api").api;
let baseUrl = getApp().globalData.baseUrl;
export const ossUploadFile = {
  async ossUploadFile(data = {}, success, onProgressUpdate) {
    let uploadTask = uni.uploadFile({
      url: baseUrl + getApp().globalData.upload, // 开发者服务器的URL。
      filePath: data.filePath,
      name: "file", // 必须填file。
      formData: {
        type: data.type,
      },
      success: (res) => {
        console.log(res);
        success(JSON.parse(res.data));
      },
      fail: (err) => {
        console.log(err);
      },
    });
    uploadTask.onProgressUpdate((res) => {
      if (typeof onProgressUpdate == "function") {
        onProgressUpdate(JSON.parse(res.data));
      }
    });
  },
};
